PHP Recursive function

 
<?php
 
function recursive(&$myarray, $dir, $recursiveDir = null) {
 
    $items = scandir($dir);
 
    foreach ($items as $item) {
 
        if ($item != "." && $item != "..") {
 
            $file = $dir. DIRECTORY_SEPARATOR. $item;
 
            if (is_dir($file)) {
                definitions($routes, $file, $file);
            }
            else {
                // get name of api        
                $expl = explode(".", $item);
 
                $key = ($recursiveDir !== null) ? basename($recursiveDir). '.'. $expl[0] : $expl[0];
                $value = $expl[1];
 
                $myarray[$key] = $value;
	}
}
 
$myarray = array();
recursive($myarray, ROOT . "app/project". DIRECTORY_SEPARATOR);
 
print_r($myarray,1);

Leave a Reply